package com.aaa.system.controller;

import com.aaa.system.entity.User;
import com.aaa.system.service.IUserService;
import com.aaa.system.vo.LoginVo;
import com.aaa.system.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @program: qy165-springboot05
 * @description:
 * @author: 闫克起2
 * @create: 2023-06-20 11:12
 **/
@RestController
@RequestMapping("/system/login")
@Api(tags = "登录的接口类")
public class LoginController {

    @Autowired
    private IUserService userService;

    @ApiOperation(value = "登录接口")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "loginVO",value = "登录的json数据")
    )
    @PostMapping
    public Result login(@RequestBody LoginVo loginVO, HttpSession session) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username", loginVO.getUsername());
        wrapper.eq("password", loginVO.getPassword());
        User user = userService.getOne(wrapper);
        if (user != null) {
            //1.保存到会话session,
            session.setAttribute("user", user);
            return new Result(200, "登录成功", null);
        }
        return new Result(500, "登录失败", null);
    }
}






















